<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<%@taglib prefix="sj" uri="/struts-jquery-tags"%>

<script type="text/javascript">

	$(document).ready(function () {
		function showSuccess(str,delay){
			if(delay){
			    $('#alertMessage').removeClass('error')
			        .html(str).stop(true,true).fadeIn()
			        .delay(delay).fadeOut(); return false;
			}
		}
		
		$('#validation_demo').submit(function(e) {
    		var $form = $(this);
            var formData = $form.serializeArray();

			var newPassword = $('#newPassword').val();
			var oldPassword = $('#oldPassword').val();
			var confirmPassword = $('#confirmPassword').val();

			if(newPassword.length > 0 && oldPassword.length > 0 && confirmPassword.length > 0) {
				$.ajax({
	                type: 'POST',
	                dataType:'json',
	                url: 'ChangePasswordAction_update.do',
	                data: formData,
	                success: function(data) {
	                   var message = data.jsonMessage;
	                   var type = data.jsonType;

	                   if(type == "Success") {
	                	   showSuccess(message);
	                	   $('#newPassword').val("");
	                	   $('#oldPassword').val("");
	                	   $('#confirmPassword').val("");
	                   } else if (message.length > 0) {
	                	   showError(message);
	                   } else {
	                	   window.location.href='LoginAction_logout.do';
	                   }
	                }
	            });
			}
			
        });
    });
        
</script>

<div class="header"><span><span class="ico gray administrator"></span>Change Password</span>
</div><!-- End header -->	
<div class="content" >
	<s:form name="formBody" id="validation_demo">
	    <s:hidden name="start"/>
	    <s:hidden name="count"/>
	    <s:hidden name="orderBy"/>
	    <s:hidden name="ascDesc"/>
	    <s:hidden name="previousPage"/>
	    <s:hidden name="actionMethod" value="%{actionMethod}"/>
	    <s:hidden name="subaction"/>
	    <s:token/>
	
		<!-- Third / Half column-->
		<div class="widgets">
		
		<div class="oneTwo">
			<div class="section ">
				<label><s:text name="label.oldPassword"/><small>Password Lama</small></label>   
				<div> 
				    <s:password cssClass="validate[required,minSize[1]] large" name="oldPassword"
	                            labelposition="left" maxlength="20" id="oldPassword" autocomplete="off"/>
				</div>
			</div>
			
			<div class="section ">
				<label><s:text name="label.newPassword"/><small>Password Baru</small></label> 
				<div> 
				    <s:password cssClass="validate[required,minSize[8]] large" name="newPassword"
	                            labelposition="left" maxlength="20" id="newPassword" autocomplete="off"/>
				</div>
			</div>
			
			<div class="section last">
	            <div>
	            	<s:reset cssClass="uibutton special" value="RESET" cssStyle="width:100px"/>
	            	<s:submit action="%{actionMethod}" value="SUBMIT" cssClass="uibutton" cssStyle="width:100px"/> 
	           	</div>
	        </div>
		</div>
			
		<div class="oneTwo">
			
			<div class="section ">
				<label><s:text name="label.newPasswordConfirmation"/><small>Konfirmasi Password</small></label>   
				<div> 
				    <s:password cssClass="validate[required,minSize[8]] large" name="confirmPassword"
	                            labelposition="left" maxlength="20" id="confirmPassword" autocomplete="off"/>
				</div>
			</div>
		  
		</div>
		
		</div><!-- End Third / Half column-->
	
	</s:form>

   <!-- clear fix -->
<div class="clear"></div>

</div><!-- End content -->